package beans;

import sqlInject.Payload;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by td on 2017/7/3.
 */
public class ErrorPayload {
    private String leadingMistakeContent;
    private List<String> mistakeContentFlag;

    private static List<ErrorPayload> errorPayloadList = null;
    private static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader( Payload.class.getClassLoader().
            getResourceAsStream("sqlerrors.txt")));

    public static List<ErrorPayload> getErrorPayloadListInstance(){
        if (errorPayloadList == null){
            errorPayloadList = new ArrayList<ErrorPayload>();
            String line = null;
            try {
                while ((line = bufferedReader.readLine())!=null&&!line.trim().equals("")){
                    ErrorPayload errorPayload = new ErrorPayload();

                    String[] strings = line.split("\\|");
                    List<String> mistake = new ArrayList<String>();
                    for (int i=0;i<strings.length;++i){
                        if (i==0){
                            errorPayload.setLeadingMistakeContent(strings[0]);
                        }else {
                            mistake.add(strings[i]);
                        }
                    }
                    errorPayload.setMistakeContentFlag(mistake);
                    errorPayloadList.add(errorPayload);
                }

                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return errorPayloadList;
        }
        return errorPayloadList;
    }

    public ErrorPayload(String leadingMistakeContent, List<String> mistakeContentFlag) {
        this.leadingMistakeContent = leadingMistakeContent;
        this.mistakeContentFlag = mistakeContentFlag;
    }

    public ErrorPayload() {
    }

    public String getLeadingMistakeContent() {
        return leadingMistakeContent;
    }

    public void setLeadingMistakeContent(String leadingMistakeContent) {
        this.leadingMistakeContent = leadingMistakeContent;
    }

    public List<String> getMistakeContentFlag() {
        return mistakeContentFlag;
    }

    public void setMistakeContentFlag(List<String> mistakeContentFlag) {
        this.mistakeContentFlag = mistakeContentFlag;
    }


}
